/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tictactoe;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

/**
 *
 * @author Kevin O
 */
public class NewGameDialog extends JDialog implements ActionListener{
    //Swing components
    private JComboBox multi_box;
    private JComboBox diff_box;
    private JPanel dialog_panel;
    private JPanel button_panel;
    private JButton newgame_button;
    private JButton cancel_button;
    
    //Stores the options chosen
    boolean single_player = true;
    int difficulty = 0;
    boolean confirmed = false;
    
    public NewGameDialog(){
        super((Frame)null, "New Game", true);
        dialog_panel = new JPanel(new BorderLayout());
        
        //Initialize the combo boxes
        String[] multi_options = { "Single Player", "Multiplayer" };
        multi_box = new JComboBox(multi_options);
        multi_box.addActionListener(this);
        String[] diff_options = { "Easy", "Medium", "Hard" };
        diff_box = new JComboBox(diff_options);
        diff_box.addActionListener(this);
        
        //Initialize the buttons and the panel that go in, so that they
        //appear side by side
        button_panel = new JPanel(new BorderLayout());
        newgame_button = new JButton("New Game");
        newgame_button.addActionListener(this);
        cancel_button = new JButton("Cancel");
        cancel_button.addActionListener(this);
        button_panel.add(newgame_button, BorderLayout.WEST);
        button_panel.add(cancel_button, BorderLayout.EAST);
        
        //Adds all of the components to the main panel
        dialog_panel.add(multi_box, BorderLayout.NORTH);
        dialog_panel.add(diff_box, BorderLayout.CENTER);
        dialog_panel.add(button_panel, BorderLayout.SOUTH);
        
        //Initialize the dialog, setting the size and the dialog variables
        this.setContentPane(dialog_panel);
        this.pack();
        this.setResizable(false);
        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    }
    
    public void actionPerformed(ActionEvent e){
        //Sets variables approriately depending on options chosen
        if(e.getSource() == multi_box){
            if(multi_box.getSelectedIndex() == 1){
                diff_box.setEnabled(false);
                single_player = false;
            }
            else{
                diff_box.setEnabled(true);
                single_player = true;
            }
        }
        
        else if(e.getSource() == diff_box){
            difficulty = diff_box.getSelectedIndex();
        }
        
        //Closes the dialog, and indicates which button was clicked
        else if(e.getSource() == newgame_button){
            this.setVisible(false);
            confirmed = true;
        }
        
        else if(e.getSource() == cancel_button){
            this.setVisible(false);
        }
                
    }
}

